package cn.bj.ykct.web;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloController {

	@RequestMapping("/hello")
	public ModelAndView helloWorld() {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/hello");
		mav.addObject("helloString", "Hello, Spring from Controller");
		return mav;
	}

	@RequestMapping("/hello2")
	public String hello2(Model model) {
		model.addAttribute("helloString", "Hello, Spring from Controller");
		return "/hello2";
	}

	@RequestMapping("/hello3")
	public String hello3(Model model, 
			@RequestParam(name = "name", required = true) String name) {
		model.addAttribute("helloString", "Hello, " + name);
		return "/hello2";
	}

	@RequestMapping(value = "/hello4", method = RequestMethod.POST)
	public String hello4(Model model, 
			@RequestParam(name = "name", required = true) String name) {
		model.addAttribute("helloString", "Hello, " + name);
		return "/hello2";
	}

	@RequestMapping(value = "/toHello4", method = RequestMethod.GET)
	public String toHello4() {
		return "/hello4";
	}
}
